#AilAg1 = login-ready voice
#AilAg2 = login-ready voice
#AilAg3 = login-ready Ag102 voice, email, chat
#AilAg4 = login-notready Ag103 email, chat
#AilAg5 = logout Ag104

#capacity rule - 10 emails

def chat_1():
  """Chat between customer and agent. Customer disconnects"""
  chat = Customer1.StartChat(GetOption("WebHost"), GetOption("ChatScript"))
  agChat = AilAg3.AcceptChat()
  Customer1.GetChatMessage("joined")
  Customer1.SendChatMessage("Message1", chat)
  AilAg3.GetChatMessage(agChat, "Message1")
  Customer1.SendChatMessage("Message2", chat)
  AilAg3.GetChatMessage(agChat, "Message2")
  AilAg3.SendChatMessage(agChat, "Message3")  
  Customer1.GetChatMessage("Message3")
  Customer1.DisconnectChat(chat)
  AilAg3.MarkDoneChat(agChat)


def chat_2():
  """Chat between customer and agent. Agent disconnects"""
  chat = Customer1.StartChat(GetOption("WebHost"), GetOption("ChatScript"))
  agChat = AilAg3.AcceptChat()
  Customer1.GetChatMessage("joined")
  AilAg3.MarkDoneChat(agChat)
  Customer1.GetChatMessage("left")
  
def chat_3():
  """Agent3 receives chat and ignores it. Chat is revoked and then delivered back to the same agent"""
  chat = Customer1.StartChat(GetOption("WebHost"), GetOption("ChatScript"))
  agChat = AilAg3.IgnoreChat()
  agChat = AilAg3.AcceptChat()
  Customer1.GetChatMessage("joined")
  AilAg3.MarkDoneChat(agChat)
  Customer1.GetChatMessage("left")  
  
def chat_4():
  """Agent3 receives chat, transfers it to Agent4, Agent4 accepts it and marks done"""
  chat = Customer1.StartChat(GetOption("WebHost"), GetOption("ChatScript"))
  agChat = AilAg3.AcceptChat()
  Customer1.GetChatMessage("joined")

  try:
    AilAg4.SetReady()
    AilAg3.TransferChatToAgent(agChat, AilAg4)
    agChat = AilAg4.AcceptChat()
    Customer1.GetChatMessage(["('" + AilAg4.userName + "') has joined", "('" + AilAg3.userName + "') has left"])
    Customer1.SendChatMessage("Message2", chat)
    AilAg4.GetChatMessage(agChat, "Message2")
    AilAg4.SendChatMessage(agChat, "Message3")  
    Customer1.GetChatMessage("Message3")    
    AilAg4.MarkDoneChat(agChat)
    Customer1.GetChatMessage("left")
  finally:
    AilAg4.SetNotReady()
      
def chat_5():
  """Agent3 receives chat, transfers it to Agent4, Agent4 ignores it, chat is sent back to Agent3"""
  chat = Customer1.StartChat(GetOption("WebHost"), GetOption("ChatScript"))
  agChat = AilAg3.AcceptChat()
  Customer1.GetChatMessage("joined")
  AilAg3.TransferChatToAgent(agChat, AilAg4)
  AilAg4.IgnoreChat()
  AilAg3.MarkDoneChat(agChat) # chat will come back without invitation
  Customer1.GetChatMessage("left")


def chat_6():
  """Agent3 receives chat, transfers it logged out Agent5, chat is sent back to Agent3"""
  chat = Customer1.StartChat(GetOption("WebHost"), GetOption("ChatScript"))
  agChat = AilAg3.AcceptChat()
  Customer1.GetChatMessage("joined")
  AilAg3.TransferChatToAgent(agChat, AilAg5)
  AilAg3.MarkDoneChat(agChat) # chat will come back without invitation
  Customer1.GetChatMessage("left")


      
def chat_7():
  """Agent3 receives chat, transfers it to the Place of Agent4, Agent4 accepts it and marks done"""
  chat = Customer1.StartChat(GetOption("WebHost"), GetOption("ChatScript"))
  agChat = AilAg3.AcceptChat()
  Customer1.GetChatMessage("('" + AilAg3.userName + "') has joined")
  try:
    AilAg4.SetReady()
    AilAg3.TransferChatToPlace(agChat, AilAg4)
    agChat = AilAg4.AcceptChat()
    Customer1.GetChatMessage(["('" + AilAg4.userName + "') has joined", "('" + AilAg3.userName + "') has left"])
    Customer1.SendChatMessage("Message2", chat)
    AilAg4.GetChatMessage(agChat, "Message2")
    AilAg4.SendChatMessage(agChat, "Message3")  
    Customer1.GetChatMessage("Message3")    
    AilAg4.MarkDoneChat(agChat)
    Customer1.GetChatMessage("('" + AilAg4.userName + "') has left")
  finally:
    AilAg4.SetNotReady()  
    
    
    
def chat_8():
  """Agent3 receives chat, conference it with Agent4, Visibility = ALL"""
  chat = Customer1.StartChat(GetOption("WebHost"), GetOption("ChatScript"))
  agChat1 = AilAg3.AcceptChat()
  Customer1.GetChatMessage("joined")

  try:
    AilAg4.SetReady()
    AilAg3.ConferenceChatWithAgent(agChat1, AilAg4, ailChatVisibility.ALL)
    agChat2 = AilAg4.AcceptChat(ailChatVisibility.ALL)
    Customer1.GetChatMessage("joined")
    Customer1.SendChatMessage("Message2", chat)
    AilAg3.GetChatMessage(agChat1, "Message2")
    AilAg4.GetChatMessage(agChat2, "Message2")
    AilAg4.SendChatMessage(agChat2, "Message3")  
    Customer1.GetChatMessage("Message3")    
    AilAg3.GetChatMessage(agChat1, "Message3")
    AilAg3.SendChatMessage(agChat1, "Message4")  
    Customer1.GetChatMessage("Message4")  
    AilAg4.GetChatMessage(agChat2, "Message4")
    AilAg4.LeaveChat(agChat2)
    Customer1.GetChatMessage("left")
    AilAg3.MarkDoneChat(agChat1)
    Customer1.GetChatMessage("left")
  finally:
    AilAg4.SetNotReady()    
    
def chat_9():
  """Agent3 receives chat, conference it with Agent4, Visibility = INT """
  chat = Customer1.StartChat(GetOption("WebHost"), GetOption("ChatScript"))
  agChat1 = AilAg3.AcceptChat()
  Customer1.GetChatMessage("joined")

  try:
    AilAg4.SetReady()
    AilAg3.ConferenceChatWithAgent(agChat1, AilAg4, ailChatVisibility.INT)
    agChat2 = AilAg4.AcceptChat(ailChatVisibility.INT)
    Customer1.SendChatMessage("Message2", chat)
    AilAg3.GetChatMessage(agChat1, "Message2")
    AilAg4.GetChatMessage(agChat2, "Message2")
    AilAg4.SendChatMessage(agChat2, "Message3")  
    AilAg3.GetChatMessage(agChat1, "Message3")
    AilAg3.SendChatMessage(agChat1, "Message4")  
    Customer1.GetChatMessage("Message4")  
    AilAg4.GetChatMessage(agChat2, "Message4")
    AilAg4.LeaveChat(agChat2)
    AilAg3.MarkDoneChat(agChat1)
    Customer1.GetChatMessage("left")
  finally:
    AilAg4.SetNotReady()   
    
def chat_10():
  """Agent3 receives chat, conference it with Agent4, Agent4 leaves chat, Agent transfer chat to Agent4"""
  chat = Customer1.StartChat(GetOption("WebHost"), GetOption("ChatScript"))
  agChat1 = AilAg3.AcceptChat()
  Customer1.GetChatMessage("joined")

  try:
    AilAg4.SetReady()
    AilAg3.ConferenceChatWithAgent(agChat1, AilAg4, ailChatVisibility.ALL)
    agChat2 = AilAg4.AcceptChat(ailChatVisibility.ALL)
    Customer1.GetChatMessage("joined")
    AilAg4.LeaveChat(agChat2)
    Customer1.GetChatMessage("left")
    AilAg3.TransferChatToAgent(agChat1, AilAg4)
    agChat2 = AilAg4.AcceptChat()
    Customer1.GetChatMessage(["('" + AilAg4.userName + "') has joined", "('" + AilAg3.userName + "') has left"])    
    Customer1.SendChatMessage("Message2", chat)
    AilAg4.GetChatMessage(agChat2, "Message2")
    AilAg4.MarkDoneChat(agChat2)
    Customer1.GetChatMessage("left")
  finally:
    AilAg4.SetNotReady()      